﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.Common.Validator;
using Shsc.Net.Common.Validator.Validators;

namespace Shsc.Net.Common.Validator.Attributes
{
    /// <summary>
    /// 验证特性基类
    /// </summary>
    public abstract class BaseValidationAttribute : Attribute
    {
        public BaseValidationAttribute()
        {
            this.ErrorMessageResourceName = Constants.ErrorMessageResourcePath;
        }

        /// <summary>
        /// 目标Action
        /// </summary>
        public string[] TagerAction { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Language { get; set; }

        /// <summary>
        /// 错误消息ID
        /// </summary>
        public string ErrorMessageId { get; set; }

        /// <summary>
        /// 错误消息资源名称
        /// </summary>
        public string ErrorMessageResourceName { get; set; }

        /// <summary>
        /// 错误消息参数
        /// </summary>
        public string[] ErrorMessageParam { get; set; }

        public Shsc.Net.Common.Validator.Validator Validator
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        /// <summary>
        /// 创建验证器
        /// </summary>
        /// <returns></returns>
        protected abstract BaseValidator CreateValidator();

        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="value"></param>
        /// <param name="name"></param>
        public void DoValidate(string ctrlId,
            object value, string objectName, string language,
            ValidatorResultList validationResults)
        {
            Language = language;
            CreateValidator().DoValidate(ctrlId,
                value, objectName, this, validationResults);
        }
    }
}
